﻿using System;
using System.IO;
using UnityEngine;

// Token: 0x02000587 RID: 1415
public class NeckLookController : MonoBehaviour
{
	// Token: 0x060021EB RID: 8683 RVA: 0x00134874 File Offset: 0x00132A74
	public virtual void Start()
	{
		if (!this.target && Camera.main)
		{
			this.target = Camera.main.transform;
		}
	}

	// Token: 0x060021EC RID: 8684 RVA: 0x001348A8 File Offset: 0x00132AA8
	public virtual void Update()
	{
	}

	// Token: 0x060021ED RID: 8685 RVA: 0x001348AC File Offset: 0x00132AAC
	public virtual void LateUpdate()
	{
		if (this.neckLookScript == null)
		{
			return;
		}
		this.neckLookScript.UpdateCall(this.ptnNo);
		if (this.target != null)
		{
			if (null != this.neckLookScript)
			{
				Vector3 position = base.transform.position;
				Vector3 position2 = this.target.position;
				for (int i = 0; i < 2; i++)
				{
					position2[i] = Mathf.Lerp(position[i], position2[i], this.rate);
				}
				this.neckLookScript.NeckUpdateCalc(position2, this.ptnNo);
			}
		}
		else
		{
			this.neckLookScript.NeckUpdateCalc(this.neckLookScript.backupPos, this.ptnNo);
		}
	}

	// Token: 0x060021EE RID: 8686 RVA: 0x00134980 File Offset: 0x00132B80
	public virtual void SaveNeckLookCtrl(BinaryWriter writer)
	{
		writer.Write(this.ptnNo);
		Quaternion fixAngle = this.neckLookScript.fixAngle;
		writer.Write(fixAngle.x);
		writer.Write(fixAngle.y);
		writer.Write(fixAngle.z);
		writer.Write(fixAngle.w);
	}

	// Token: 0x060021EF RID: 8687 RVA: 0x001349DC File Offset: 0x00132BDC
	public virtual void LoadNeckLookCtrl(BinaryReader reader)
	{
		this.ptnNo = reader.ReadInt32();
		Quaternion fixAngle = new Quaternion(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
		this.neckLookScript.SetFixAngle(fixAngle);
	}

	// Token: 0x04002A69 RID: 10857
	public global::NeckLookCalc neckLookScript;

	// Token: 0x04002A6A RID: 10858
	public int ptnNo;

	// Token: 0x04002A6B RID: 10859
	public Transform target;

	// Token: 0x04002A6C RID: 10860
	public float rate = 1f;
}
